package com.example.kotlincourse

import android.os.Bundle
import android.view.LayoutInflater
import android.widget.Toast
import com.example.commonbiz.BaseVMActivity
import com.example.commonbiz.LoginViewModel
import com.example.commonbiz.RequestUser
import com.example.commonbiz.User
import com.example.kotlincourse.databinding.ActivityLoginBinding

class LoginActivity : BaseVMActivity<LoginViewModel, ActivityLoginBinding>() {

    override fun getViewModelClass() = LoginViewModel::class.java

    override fun inflateBinding(layoutInflater: LayoutInflater) =
        ActivityLoginBinding.inflate(layoutInflater)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        initView()
    }

    private fun initView() {

        binding.btnLogin.setOnClickListener {
            val name: String = binding.edtPhone.text.toString()
            if (name.isEmpty()) {
                Toast.makeText(baseContext, "账号不能为空", Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }
            Toast.makeText(baseContext, "login：" + name, Toast.LENGTH_SHORT).show()

            var user:RequestUser = RequestUser(name)
            viewModel.login(user)
        }
    }
}